package logic

import (
	"box-mart-api/models/mysql"
	"context"
	"errors"

	"box-mart-api/boxrpc/boxrpc"
	"box-mart-api/boxrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type BoxDeleteLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBoxDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BoxDeleteLogic {
	return &BoxDeleteLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 删除
func (l *BoxDeleteLogic) BoxDelete(in *boxrpc.BoxDeleteRequest) (*boxrpc.BoxDeleteResponse, error) {
	// todo: add your logic here and delete this line
	var box mysql.Box
	err := box.BoxDetail(mysql.DB, in.BoxId)
	if err != nil {
		return nil, errors.New("不存在商品,不允许删除")
	}
	err = box.BoxDel(mysql.DB, in.BoxId)
	if err != nil {
		return nil, err
	}
	return &boxrpc.BoxDeleteResponse{}, nil
}
